package com.ruoyi.project.search.viewCargoStatistics.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.search.viewCargoStatistics.domain.ViewCargoStatistics;
import com.ruoyi.project.search.viewCargoStatistics.service.IViewCargoStatisticsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货位统计表Controller
 * 
 * @author ruoyi
 * @date 2024-04-23
 */
@Controller
@RequestMapping("/search/viewCargoStatistics")
public class ViewCargoStatisticsController extends BaseController
{
    private String prefix = "search";

    @Autowired
    private IViewCargoStatisticsService viewCargoStatisticsService;

    @GetMapping()
    public String viewCargoStatistics()
    {
        return prefix + "/viewCargoStatistics";
    }

    /**
     * 查询货位统计表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewCargoStatistics viewCargoStatistics)
    {
        startPage();
        List<ViewCargoStatistics> list = viewCargoStatisticsService.selectViewCargoStatisticsList(viewCargoStatistics);
        return getDataTable(list);
    }

    /**
     * 导出货位统计表列表
     */
    @Log(title = "货位统计表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewCargoStatistics viewCargoStatistics)
    {
        List<ViewCargoStatistics> list = viewCargoStatisticsService.selectViewCargoStatisticsList(viewCargoStatistics);
        ExcelUtil<ViewCargoStatistics> util = new ExcelUtil<ViewCargoStatistics>(ViewCargoStatistics.class);
        return util.exportExcel(list, "货位统计表数据");
    }

    /**
     * 新增货位统计表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货位统计表
     */
    @Log(title = "货位统计表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewCargoStatistics viewCargoStatistics)
    {
        return toAjax(viewCargoStatisticsService.insertViewCargoStatistics(viewCargoStatistics));
    }

    /**
     * 修改货位统计表
     */
    @GetMapping("/edit/{warehouseId}")
    public String edit(@PathVariable("warehouseId") String warehouseId, ModelMap mmap)
    {
        ViewCargoStatistics viewCargoStatistics = viewCargoStatisticsService.selectViewCargoStatisticsByWarehouseId(warehouseId);
        mmap.put("viewCargoStatistics", viewCargoStatistics);
        return prefix + "/edit";
    }

    /**
     * 修改保存货位统计表
     */
    @Log(title = "货位统计表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewCargoStatistics viewCargoStatistics)
    {
        return toAjax(viewCargoStatisticsService.updateViewCargoStatistics(viewCargoStatistics));
    }

    /**
     * 删除货位统计表
     */
    @Log(title = "货位统计表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewCargoStatisticsService.deleteViewCargoStatisticsByWarehouseIds(ids));
    }
}
